package com.service.impl;

import com.bean.entity.StudentScore;
import com.bean.pojo.PageAssistant;
import com.bean.vo.StudentScoreVo;
import com.dao.StudentScoreMapper;
import com.service.StudentScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class StudentScoreServiceImpl implements StudentScoreService {

    @Autowired
    private StudentScoreMapper studentScoreMapper;

    @Override
    public int save(StudentScore t) throws Exception {
        int insert = studentScoreMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("学生分数添加失败！请重新输入！");
    }

    @Override
    public int remove(StudentScore t) throws Exception {
        int delete = studentScoreMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("您要删除的学生分数失败，请重新操作！");
    }

    @Override
    public int modify(StudentScore t) throws Exception {
        int update = studentScoreMapper.update(t);
        if (update==1) return 1;
        throw new Exception("学生分数修改失败！");
    }

    @Override
    public StudentScoreVo unique(StudentScore t) throws Exception {
        List<StudentScoreVo> select = studentScoreMapper.select(t);
        if (select.size()!=1) throw new Exception("您要查询的学生分数暂未找到！");
        return select.get(0);
    }

    @Override
    public List<StudentScoreVo> query(StudentScore t) {
        return studentScoreMapper.select(t);
    }

    @Override
    public PageAssistant<StudentScoreVo> queryByPage(Map<String, Object> map, PageAssistant<StudentScoreVo> pa) {
        //查询并设置总记录数
        pa.setCount(studentScoreMapper.selectCount(map));
        //添加分页参数
        map.put("startCode",pa.getStartCode());
        map.put("pageSize",pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(studentScoreMapper.selectByPage(map));
        return pa;
    }
}
